package com.ymatou.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.auth.service.LoginAuthCall;
import com.ymatou.userservice.parameter.PasswordResetRequestDtoBean;
import com.ymatou.userservice.service.PasswordResetRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AuthCallService;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
/**
*重置用户登录密码用例
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_PasswordResetRequestDto{
	private static PasswordResetRequestDtoBean passwordresetrequestdtoBean;
	private static PasswordResetRequestDtoCall passwordresetrequestdtoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("重置用户登录密码用例");
	}

	@Before
	public void caseUp() {
		passwordresetrequestdtoBean=new PasswordResetRequestDtoBean();
		passwordresetrequestdtoCall=new PasswordResetRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(passwordresetrequestdtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_PasswordResetRequestDto_001() {
		Logger.start(true,"重置用户登录密码");
		try {
	
			String userId=EnvSetup.getData("loginUserId");
			String userName=EnvSetup.getData("loginUserName");			
			String password=TestDataManager.getRandomNum(10);

			passwordresetrequestdtoBean.setUserId(userId);
			passwordresetrequestdtoBean.setNewPassword(password);
			
			passwordresetrequestdtoCall.setData(passwordresetrequestdtoBean);
			passwordresetrequestdtoCall.callService();			
			
			Logger.verifyEquals("ok", passwordresetrequestdtoCall.getSuccessMessage(), "验证SuccessMessage");
			Logger.verifyEquals("200", passwordresetrequestdtoCall.getResponseCode(), "验证ResponseCode");
			Logger.verifyEquals("true", passwordresetrequestdtoCall.getSuccess(), "验证Success");
			Logger.verifyEquals("Success", passwordresetrequestdtoCall.getResult(), "验证Result");

			Thread.sleep(5000);
			 new AuthCallService().authIPArea("172.16.101.11", userName, password, "mainsite");
			LoginAuthCall loginAuthCall = new AuthCallService().login(userName, password,"mainsite","172.16.101.11");
			Logger.verifyEquals(true, loginAuthCall.getSuccess(), "验证登录成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_PasswordResetRequestDto_002() {
		Logger.start(true,"重置用户登录密码-userId空");
		try {
			
			String password=TestDataManager.getRandomNum(10);

			passwordresetrequestdtoBean.setNewPassword(password);
			
			passwordresetrequestdtoCall.setData(passwordresetrequestdtoBean);
			passwordresetrequestdtoCall.callService();			
			
			Logger.verifyEquals("请求数据错误", passwordresetrequestdtoCall.getLastErrorMessage(), "验证LastErrorMessage");
			Logger.verifyEquals("400", passwordresetrequestdtoCall.getResponseCode(), "验证ResponseCode");
			Logger.verifyEquals("false", passwordresetrequestdtoCall.getSuccess(), "验证Success");
			Logger.verifyEquals("UserIdError", passwordresetrequestdtoCall.getResult(), "验证Result");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_PasswordResetRequestDto_003() {
		Logger.start(true,"重置用户登录密码-password空");
		try {
			
			String userId=EnvSetup.getData("loginUserId");
			passwordresetrequestdtoBean.setUserId(userId);
			
			passwordresetrequestdtoCall.setData(passwordresetrequestdtoBean);
			passwordresetrequestdtoCall.callService();			
			
			Logger.verifyEquals("请求数据错误", passwordresetrequestdtoCall.getLastErrorMessage(), "验证LastErrorMessage");
			Logger.verifyEquals("400", passwordresetrequestdtoCall.getResponseCode(), "验证ResponseCode");
			Logger.verifyEquals("false", passwordresetrequestdtoCall.getSuccess(), "验证Success");
			Logger.verifyEquals("NewPasswordEmpty", passwordresetrequestdtoCall.getResult(), "验证Result");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_PasswordResetRequestDto_004() {
		Logger.start(true,"重置用户登录密码-userId不存在");
		try {
	
			String password=TestDataManager.getRandomNum(10);

			passwordresetrequestdtoBean.setUserId("888888888");
			passwordresetrequestdtoBean.setNewPassword(password);
			
			passwordresetrequestdtoCall.setData(passwordresetrequestdtoBean);
			passwordresetrequestdtoCall.callService();			
			
			Logger.verifyEquals("用户不存在", passwordresetrequestdtoCall.getLastErrorMessage(), "验证LastErrorMessage");
			Logger.verifyEquals("400", passwordresetrequestdtoCall.getResponseCode(), "验证ResponseCode");
			Logger.verifyEquals("false", passwordresetrequestdtoCall.getSuccess(), "验证Success");
			Logger.verifyEquals("UserNotFind", passwordresetrequestdtoCall.getResult(), "验证Result");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}